package JsonHelper

import (
	"ShortLink/Core/LogHelper"
	"encoding/json"
)

func SerializeObject(obj interface{}) string {
	jsonData, err := json.Marshal(obj)
	if err != nil {
		log := new(LogHelper.LogInfo)
		log.Title = "序列化失败"
		log.Msg = err.Error()
		log.Data = obj
		LogHelper.Error(log)
		return ""
	}
	return string(jsonData)
}

func DeserializeObject(data string, v any) {
	err := json.Unmarshal([]byte(data), v)
	if err != nil {
		log := new(LogHelper.LogInfo)
		log.Title = "序列化失败"
		log.Msg = err.Error()
		log.Data = data
		LogHelper.Error(log)
	}
}
